# -*- coding: utf-8 -*-

import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('picture.png')

blur = cv2.blur(img,(3,3))  #均值滤波，简单的平均卷积操作,通常用奇数
box1 = cv2.boxFilter(img,-1,(3,3),normalize=True)    #方框滤波，基本和均值滤波一样，可选择归一化
box2 = cv2.boxFilter(img,-1,(3,3),normalize=False)    #方框滤波，基本和均值滤波一样，可选择归一化容易越界,越界时大于255的值在图像中显示为全白
aussian = cv2.GaussianBlur(img,(5,5),1)             #高斯滤波，高斯模糊的卷积核里的数值满足卷积的高斯分布，相当于重视中间的
#卷积核就是[n,n]
median = cv2.medianBlur(img,5)      #中值滤波，相当于用中值代替

res = np.hstack((blur,aussian,median))
res2 = np.hstack((blur,box1,box2))
cv2.imshow('picture-1',res)
cv2.imwrite('picture-1.png',res)
cv2.waitKey(0)
cv2.imshow('picture-2',res2)
cv2.imwrite('picture-2.png',res2)
cv2.waitKey(0)
cv2.destroyAllWindows()